<?php

	/*
	  Initilizing file
	*/

	require_once(PATCH_LIBS.'FirePHPCore/fb.php');	
	
	# Autoload init
		function __autoload($class_name) {
			$fn = str_replace('__kernel_', PATCH_KERNEL.'classes/', $class_name);
			$fn = str_replace('__lib_',    PATCH_LIBS,   $fn);
			$fn = str_replace('__module_', './modules/',  $fn);
			$fn = str_replace('__driver_', PATCH_DRIVERS,  $fn);
			
			$explode   = explode('_', $class_name);
			
			if(isset($explode[4])) {
				$class = '.'.$explode[4];
				$fn = str_replace('_'.$explode[4], '',  $fn);
			} else $class = '.class';
			
			if($explode[2] == 'lib') {
				$fn = str_replace('_',        '/', $fn).'.class.php';
			} elseif($explode[0] == 'MT' || $explode[0] == 'KT' || $explode[0] == 'DT') {
				
				    if($explode[0] == 'MT') $fn = './modules';				// Module Types
				elseif($explode[0] == 'KT') $fn = PATCH_KERNEL.'classes';	// Kernel Types
				elseif($explode[0] == 'DT') $fn = PATCH_DRIVERS;			// Driver Types
				
				$count = count($explode);
				if($count == 3) {
					$fn .= "/{$explode[1]}/types/{$explode[1]}.types.php";
				} elseif($count == 4) {
					$fn .= "/{$explode[1]}/types/{$explode[1]}.{$explode[2]}.types.php";
				} else return false;
				
				$h=@fopen($fn,'r',true);
				if($h===false) {
					return false;
				}
			
				fclose($h);
				require_once($fn);
			} else {
				$fn = str_replace('_', '/', $fn).'/'.$explode[3].$class.'.php';
				$this_module = true;
			}

			if(is_file($fn)) {
                require_once($fn);
			    $module = explode("_", $class_name);
			    if($module[2] == "module") {
			        $module_ = $module[3];
			        if(isset($module[4])) $module_ = array($module_, $module[4]);
			    }
			} else {
			        //echo "$fn";
			        return false;
			}
			
			

			return true;
		}

	# Initilize "afterBase" configuration
	    $config['class'] = new __seng_config();
		
	# Start kernel-init class
		if($_GET['m']  == 'main') {
			$_GET['m'] =  '';
		}
		
		$init['class']   = new __kernel_init();
		$init['class'] -> start();
		
		if($_SERVER['HTTP_REMOTE'] == 'soul_remote_protocol') {
			echo __kernel_remote::returnData();
				 save_session_now();
			exit();
		}
		
		$init['display'] = $init['class']->display;
		
	# Kernel work display
		# Create JavaScrpt url
			$jscript = &__kernel_init::$jscript;
			foreach($jscript as $Jnom=>$Jname) {
				if(@fopen("script/".$Jname, "r"))
					$script.="<script src=\"script/".$Jname."\"></script>";
			}
			
		# Display template
			$_SESSION['js'] = $init['blocks']['js'];
			$init['display']['script'] = "<script>".$init['blocks']['js']."</script>";//$script;
			
			__driver_display::si()->assign('index', $init['display']);			__driver_display::si()->display(drv(DISP)->getIndexTemplate());
				
	save_session_now();
?>
